const exam = require('../control/examination')

async function addExam(req,res){
    const {exam_name,exam_description,exam_open_time,exam_close_time,limit_time,org_id,tp_id,username} = req.body
    let result = await exam.addExam(exam_name,exam_description,exam_open_time,exam_close_time,limit_time,org_id,tp_id,username);
    res.send(result);
}

async function examList(req,res){
    const {page,pageSize,username} = req.query
    let result = await exam.examList(page,pageSize,username);
    res.send(result);
}

async function examDetail(req,res){
    const {exam_id,username} = req.query
    let result = await  exam.examDetail(exam_id,username);
    res.send(result);
}

async function updateExam(req,res){
    const {exam_id,exam_name,exam_description,exam_open_time,exam_close_time,limit_time,org_id,tp_id,username} = req.body
    let result = await exam.updateExam(exam_id,exam_name,exam_description,exam_open_time,exam_close_time,limit_time,org_id,tp_id,username);
    res.send(result);
}

async function deleteExam(req,res){
    const {exam_id,username} = req.body
    let result = await exam.deleteExam(exam_id,username);
    res.send(result);
}

async function myExamList(req,res){
    const {page,pageSize,username} = req.query
    let result = await exam.myExamList(page,pageSize,username)
    res.send(result);
}

async function takeExam(req,res){
    const {exam_id,username} = req.body
    let result = await exam.takeExam(exam_id,username)
    res.send(result);
}

async function examPaper(req,res){
    const {exam_id,username} = req.query
    let result = await exam.examPaper(exam_id,username)
    res.send(result);
}

async function saveAnswerPaper(req,res){
    const {exam_id,aq_array,username} = req.body
    let result = await exam.saveAnswerPaper(exam_id,aq_array,username);
    res.send(result);
}

async function handInPaper(req,res){
    const {exam_id,username} = req.body
    let result = await exam.handInPaper(exam_id,username)
    res.send(result);
}

async function myAnswerPaper(req,res){
    const {exam_id,username} = req.query
    let result = await exam.myAnswerPaper(exam_id,username)
    res.send(result);
}

module.exports = {
    addExam,
    examList,
    examDetail,
    updateExam,
    deleteExam,
    myExamList,
    takeExam,
    examPaper,
    saveAnswerPaper,
    handInPaper,
    myAnswerPaper
}